import { reactive } from 'vue'
import { useI18n } from '@/hooks/web/useI18n'
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import { required } from '@/utils/formRules'
import { VxeCrudSchema, useVxeCrudSchemas } from '@/hooks/web/useVxeCrudSchemas'
const modelGlobalOptions = getIntDictOptions(DICT_TYPE.CMS_MODEL_GLOBAL)
const modelTypeOptions = getIntDictOptions(DICT_TYPE.CMS_MODEL_TYPE)
const { t } = useI18n() // 国际化
// 表单校验
export const rules = reactive({
  name: [required],
  tplPrefix: [required],
  isGlobal: [required],
  status: [required],
  modelType: [required],
  sort: [required],
  createUser: [required],
  deletedFlag: [required]
})
// CrudSchema
const crudSchemas = reactive<VxeCrudSchema>({
  primaryKey: 'id', // 默认的主键ID
  primaryTitle: t('common.index'), // 默认显示的值
  primaryType: 'seq', // 默认为seq，序号模式
  action: true,
  actionWidth: '400', // 3个按钮默认200，如有删减对应增减即可
  columns: [
    {
      title: '名称',
      field: 'name',
      isSearch: true
    },
    {
      title: '模板前缀',
      field: 'tplPrefix',
      isSearch: false
    },
    {
      title: '是否全局',
      field: 'isGlobal',
      dictType: DICT_TYPE.CMS_MODEL_GLOBAL,
      dictClass: 'number',
      form: {
        component: 'Select',
        componentProps: {
          options: modelGlobalOptions
        }
      },
      isSearch: true
    },
    {
      title: '开启状态',
      field: 'status',
      isSearch: true,
      dictType: DICT_TYPE.COMMON_STATUS,
      dictClass: 'number'
    },
    {
      title: '模型类型',
      field: 'modelType',
      dictType: DICT_TYPE.CMS_MODEL_TYPE,
      dictClass: 'number',
      form: {
        component: 'Select',
        componentProps: {
          options: modelTypeOptions
        }
      }
    },
    {
      title: '排序值',
      field: 'sort',
      form: {
        component: 'InputNumber',
        value: 0
      },
      isSearch: false
    },
    {
      title: '创建时间',
      field: 'createTime',
      isForm: false,
      formatter: 'formatDate',
      search: {
        show: false,
        itemRender: {
          name: 'XDataTimePicker'
        }
      }
    }
  ]
})
